import { UICtrl } from "./BaseCtrl";
import { BaseModel } from "./BaseModel";
import { GameFacade } from "./GameFacade";
import { puremvc } from "./puremvc";
import { Ctor, RegistPMVC } from "./RegistFunc";


export class CMD<T = void> extends puremvc.SimpleCommand {
    protected static getCtrl<T>(ctrl: Ctor<T>) {
        if (!RegistPMVC.isExecuted)
            console.error("PMVC还未execute！");
        if (!RegistPMVC.viewComMap.has(ctrl)) {
            console.error("未注册Ctrl:", ctrl.name);
        }
        let com = RegistPMVC.viewComMap.get(ctrl);
        if (!com) {
            console.error("未继承BaseCtrl:", ctrl.name);
        }
        return com as UICtrl<T>;
    }
    protected static getMod<T extends BaseModel>(ctor: Ctor<T>) {
        if (!RegistPMVC.isExecuted)
            console.error("PMVC还未execute！");
        return puremvc.Facade.getInstance(GameFacade.name).retrieveProxy(ctor.name) as T;
    }
    execute(notification: any): void {
        this.do(notification.getBody());
    }
    do(param: T) {
    }
}
